-- kill_summon
-- create by cheny3
-- 道具：先试图杀死怪物，再召唤

return {
    apply = function(source, target, classId, value)
        -- 传入攻击者信息
        local assailantInfo = {
            ["property_id"] = classId,
        };

        -- 试图杀死的怪物
        local monsterId = value["monster"];
        local targetPos;
        if type(monsterId) == "number" then
            for pos = 1, GRID_SIZE do
                repeat

                    local grid = DungeonM.getGridByPos(pos);
                    local monster = grid.monster;

                    -- 不是指定的怪物或者怪物已经死亡了
                    if not grid:isOpened() or
                        not grid:isMonster() or
                        not monster or
                        monster:query("base_class_id") ~= monsterId or
                        monster:isDead() then
                        break;
                    end

                    -- 修正伤害值
                    local damage = monster:getHp();

                    -- 修正伤害值
                    damage = PropertyM.fixPropertyDamage(source, monster, classId, damage);

                    CombatM.doDamage(source, monster, damage, 0, false, { assailantInfo = assailantInfo, });

                    -- SUMMON位置,附近选一个
                    targetPos = SummonM.findSummonPos(pos);
                until true;

                if targetPos then
                    -- 干掉一个就可以了
                    break;
                end
            end
        end

        -- 召唤兽位置
        local para = {};
        if type(targetPos) == "number" then
            para["pos"] = targetPos;
        end

        -- 清除玩家负面状态
        if value["clear_debuff"] and value["clear_debuff"] == 1 then
            -- 清空负面状态
            CombatStatusM.clearStatusByType(source, COM_STATUS_DEBUFF);
            CombatStatusM.clearStatusByType(source, COM_STATUS_DAMAGE);
            -- 清空debuff
            PropM.deleteProp(source, "debuff");
        end

        -- 召唤兽信息
        local summonId = value["summon"];

        return SummonM.doSummon(summonId, para);
    end,
};
